#
# This file is part of the kernelstudio package.
#
# (c) 2014-2025 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.
#
import logging
import typing as t

from flask_restful import Api, Resource
from werkzeug.wrappers import Response as ResponseBase

from ksai.web.responses import response_success, response_error, ApiResponse

logger = logging.getLogger(__name__)


class ParametersBindableResource(Resource):
    def dispatch_request(self, *args: t.Any, **kwargs: t.Any) -> ResponseBase:
        # 可在此处添加参数绑定逻辑
        return super().dispatch_request(*args, **kwargs)

    def make_success(
            self,
            result: t.Optional[t.Any] = None,
            message: t.Optional[str] = None
    ) -> ApiResponse:
        return response_success(result=result, message=message)

    def make_error(
            self,
            message: t.Optional[str] = None,
            status: int = 400,
            code: t.Union[int, str] = "400",
            result: t.Optional[t.Any] = None
    ) -> ApiResponse:
        return response_error(
            status=status,
            code=code,
            message=message,
            result=result
        )


class ApiEndpoint(Api):
    pass
    # def make_response(self, data: t.Any, *args: t.Any, **kwargs: t.Any):
    #     if isinstance(data, ResponseBase):
    #         return super().make_response(data, *args, **kwargs)
    #     if isinstance(data, JsonSerializable):
    #         return super().make_response(data.serialize(), *args, **kwargs)
    #     return super().make_response(data, *args, **kwargs)
